from dataprocess.task.DocsIngestTask import process_document
from Logger import Logger

logger = Logger.get_logger(__name__)

class FileEventHandler:
    """Event handler for task-related events"""

    def __init__(self):
        # 订阅文件上传事件
        logger.info("Initialized FileEventHandler and subscribed to file events")
    
    @staticmethod
    async def handle(messages: dict):
            """Handle file uploaded event by starting document processing task"""
            try:
                file_path = messages.get("file_path")
                if not file_path:
                    logger.error("No file path in messages")
                    return

                logger.info(f"Starting document processing task for: {file_path}")
                # 启动 Celery 任务
                process_document.delay(messages)  
            except Exception as e:
                logger.error(f"Error handling file upload event: {str(e)}")
